package ru.paswd.marketprice.rest.app.utils;

import lombok.experimental.UtilityClass;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

@UtilityClass
public class ListUtils {
    public <T> List<T> toList(Iterable<T> iterable) {
        return StreamSupport.stream(iterable.spliterator(), false)
                .collect(Collectors.toList());
    }

    public <T, R> List<R> mapToList(Iterable<T> iterable, Function<? super T, ? extends R> converter) {
        return StreamSupport.stream(iterable.spliterator(), false)
                .map(converter)
                .collect(Collectors.toList());
    }
}
